package org.krishna.Filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LibraryFilter implements Filter{
	
	private static final Logger LOGGER = LoggerFactory.getLogger(LibraryFilter.class);
	
	@SuppressWarnings("unused")
	private FilterConfig filterConfig = null;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = ((HttpServletRequest) request);
		String Url = req.getRequestURL().toString();
        String queryString = req.getQueryString();
        String contextPath = req.getContextPath();
        
		LOGGER.info("Request from IP["+request.getRemoteHost()+"] for the URL ["+Url+"] with a context Path ["+contextPath+"] and query String ["+queryString+"]");
		chain.doFilter(request, response);
		
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
